<?php

declare(strict_types=1);

namespace owns\enum;

use app\service\system\file\FileManage;
use think\facade\Cache;

class FileEnum
{
    public const IMAGE = 'image'; //图片
    public const VIDEO = 'video'; //视频
    public const AUDIO = 'audio'; //音频
    public const OTHER = 'other'; //其他文件
    public const TEMP = 'temp'; //临时文件

    public const MB = 1048576; //1MB

    public static function dirtype()
    {
        return [
            self::IMAGE, self::VIDEO, self::AUDIO, self::OTHER, self::TEMP
        ];
    }
    /**
     * 文件cdn
     */
    public static function cdn(): string
    {
        $cdn = Cache::get(CacheMap::FIEL_CDN);
        if (!$cdn) {
            $cdn = make(FileManage::class)->domain;
            Cache::set(CacheMap::FIEL_CDN, $cdn, 10);
        }
        return $cdn;
    }
    /**
     * 文件归类
     * @param string $suffix
     */
    public static function classify(string $suffix): string
    {
        return match ($suffix) {
            'jpg', 'png', 'bmp', 'jpeg', 'gif', 'webp' => self::IMAGE, //图片类文件
            'mp4', 'avi', 'mov', 'mpeg' => self::VIDEO, //视频类文件
            'mp3', 'wav' => self::AUDIO, //音频类文件
            'zip', 'rar', 'xls', 'xlsx', 'doc', 'docx', 'pdf' => self::OTHER, //其他文件
            default => self::TEMP, //临时文件
        };
    }
}
